<template>
  <view>
    <el-table @row-click="clickRow" ref="refTable" :data="list" @selection-change="handleSelectionChange" height="400px">
      <el-table-column type="selection" width="55"></el-table-column>
      <el-table-column label="ID" prop="id" :show-overflow-tooltip="true" />
      <el-table-column label="名称" prop="name" :show-overflow-tooltip="true" />
      <el-table-column label="介绍" prop="desc" :show-overflow-tooltip="true" />
    </el-table>
  </view>
</template>

<script setup>
import request from "@/utils/request";
import { onMounted, defineProps } from "vue";
const emit = defineEmits(["confirm", "data"]);
const { proxy } = getCurrentInstance();
const props = defineProps({
  list: {
    type: Array,
  },
  data: {
    type: Object,
  },
});
// 多选框选中数据
function handleSelectionChange(selection) {
  //proxy.$refs["refTable"].clearSelection();
  var list = selection.map((item) => item.id);
  if (list.length == 1) {
    let id = list[0];
    let obj = null;

    props.list.forEach((ele) => {
      if (ele.id == id) {
        obj = ele;
      }
    });
    emit("update:data", obj);
  }
}
</script>
